
************
* Baseline
************
forval i = 1/7 {
*	local i = "1"
	insheet using "$est/Derivatives_1s_`i'.csv", clear nonames
	rename v1 ind
	rename v2 nic

	rename v3 frac_contract
	rename v4 N_i
	rename v5 N_f 
	rename v6 Lbar_i
	rename v7 Lbar_f
	rename v8 Lvar_i
	rename v9 Lvar_f
	rename v10 coeff
	
	gen i = `i'
	order i
	tempfile file`i'
	save `file`i'', replace
}

use `file1', clear 
forval i = 2/7 {
	append using `file`i'', force 
}

la def li 1 "Baseline" 2 "sigma_x" 3 "sigma_e" 4 "Theta" 5 "Phi" 6 "Bc" 7 "Br"
la val i li 

***************************************
* TAKING MEANS ACROSS EACH SIMULATION
***************************************
global varlist = "frac_contract-coeff"
gcollapse (mean) $varlist , by(i)


foreach var of varlist $varlist {
*	local var = "N_i"
	gen temp = `var' if i == 1
	egen temp2 = max(temp)
	
	gen d`var' = abs((`var'- temp2)/temp2 * 100)
	drop temp*
}

drop if i == 1
drop dN* 

keep i d*
order dLvar_i dLvar_f dLbar*, after(i)

mkmat dLvar_i dLvar_f dLbar* dcoeff dfrac_contract, matrix(T)
mat U = T'

frmttable using "${output}/calibration/TableA18.tex", statmat(U) sdec(2, 2, 2, 2, 2, 2) ///
	ctitle(" " "$\sigma, x$", "$\sigma, \varepsilon$", "$\theta$", "$\phi$", "bc", "br") ///
	rtitle("Var. Firm-size (Informal)"\"Var. Firm-size (Formal)"\"Avg. Firm-size (Informal)"\"Avg. Firm-size (Formal)"\"Coeff. On Ln(FirmSize) Sq."\"Frac. Contract Workers") ///
	replace tex pretext(" ") fragment


